package org.xa3apm.vote.hibernate.bean;

import java.io.Serializable;
import java.util.Collection;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.xa3apm.vote.hibernate.entities.Address;

@Stateless
public class AddressBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7176257122449028935L;

	@PersistenceContext(unitName = "vote")
	private EntityManager em;

	public Address getById(Long id) {
		return (Address) (em.createNamedQuery("Address.getById").setParameter(
				"Id", id).getSingleResult());
	}

	public Collection<Address> getAll() {
		@SuppressWarnings("unchecked")
		Collection<Address> resultList = em.createNamedQuery("Address.getAll")
				.getResultList();
		return resultList;
	}
}
